package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.AccountFlowListBean;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.clientCenter.queryBean.UserChangeQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;
/**
 * 用户账户流水查询
 * @author 甄玉晴
 *
 */
public class AccountFlowList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			@SuppressWarnings("rawtypes")
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
			UserChangeQueryBean bean = JsonUtils.objectToPojo(req.getData(), UserChangeQueryBean.class);
			// 校验为空判断,待确定
			// TODO Auto-generated method stub
			UserInfoMapper mapper = factory.getMapper(UserInfoMapper.class);
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			List<AccountFlowListBean> list = mapper.accountFlowList(bean);
			Map<String, String> cht = Tools.mapDicByCode(factory, "CHT");//用户状态
			if(list!=null && list.size()>0) {
				for(AccountFlowListBean accountFlowListBean:list) {
					accountFlowListBean.setPayType(cht.get(accountFlowListBean.getPayType()));
				}
			}
			info.setData(new PageInfo<>(list));
			return info;
		} catch (Exception e) {
			logger.error("用户账户流水查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
